package com.shishuo.cms.tag;

import static freemarker.template.ObjectWrapper.BEANS_WRAPPER;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shishuo.cms.entity.ClassesEntity;
import com.shishuo.cms.plugin.TagPlugin;
import com.shishuo.cms.service.ClassesService;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;

@Service
public class ClassesTag extends BaseTagPlugin {
	
	public void execute(Environment env, Map params, TemplateModel[] loopVars,
			TemplateDirectiveBody body) throws TemplateException, IOException {
		//String key = params.get("key").toString();
		try
		{
			long fatherId = Long.parseLong(params.get("fatherId").toString());
			List<ClassesEntity> classesEntityList=classesService.getChildClasses(fatherId);
			env.setVariable("tag_value", BEANS_WRAPPER.wrap(classesEntityList));
			body.render(env.getOut());
		}
		catch (Exception e)
		{
			
		}
	}
}
